/*
 * @lc app=leetcode.cn id=121 lang=golang
 *
 * [121] 买卖股票的最佳时机
 */

// @lc code=start

import "math"

func maxProfit(prices []int) int {
	// m := 0
	buy := math.MaxInt32
	sell := math.MinInt32
	for i := 0; i < len(prices); i++ {
		buy = min(buy, prices[i])
		sell = max(sell, prices[i]-buy)
		// m = max(m, sell-buy)
	}
	return sell
}

func max(i, j int) int {
	if i > j {
		return i
	}
	return j
}

func min(i, j int) int {
	if i < j {
		return i
	}
	return j
}

// @lc code=end
